package multimanipulators.finders;

import java.io.OutputStreamWriter;

import multimanipulators.interfaces.Converters;
import multimanipulators.interfaces.Finders;
/**
 * @author Lieven Roegiers
 * @copyright 2009
 * @project javamylibs
 * @from http://javamylibs.googlecode.com/svn/trunk/
**/
public class Finder_HTMLTAG_ALFA implements Finders{	
	private static final long serialVersionUID = -369326208594339865L;
		public String name ="Finder";
		public boolean isstart;
		public char first = '<';
		public char last = '>';
		public char end = '/';
		public boolean ismatch;
		public int recklok;
		private Converters converter;
		//private myfinder rec;

		public void init (){
			ismatch = false;
			isstart = false;
		}
		public Finder_HTMLTAG_ALFA(boolean endtag) {
			init();
		}
		public Finder_HTMLTAG_ALFA(boolean endtag,Converters converter) {
			this.converter= converter;
			init();
		}
		public boolean ismatchfound(){
			return ismatch;
		}
		public String toString() {
			return new String("<FIND:"+first+"&then:"+last+">");
		}
		public String getTofind(){
			return new String("'"+first+"'this'"+"'"+last+"'");
		}
		public boolean isnext(int achar){
			if(ismatch){ismatch = false;}
				return(isvalid((char)achar));
		}
		private boolean isvalid(char achar){
			if(isstart || achar == first){
				isstart = true;			
				if(achar == last ){	
					ismatch =  true;
				}
				return true;
			}else{
				return false;
			}
		}
		public void setConverter(Converters converter) {
			this.converter= converter;
		}
		public void convert(char[] data, OutputStreamWriter doutstream) throws Exception {
			converter.manipulate(data, doutstream);
		}
		@Override
		public int compareTo(Object o) {
			// TODO Auto-generated method stub
			return 0;
		}
		public int getusedbuferlength() {
			return recklok;
		}
		@Override
		public int getusedbufferlength() {
			// TODO Auto-generated method stub
			return 0;
		}
	}

